package com.ruoyi.web.controller.memberCoupon;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.StoredValueCard;
import com.ruoyi.system.service.IStoredValueCardService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 储值卡 Controller
 *
 * @author ruoyi
 * @date 2025-05-22
 */
@Api(tags="储值卡")
@RestController
@RequestMapping("/system/storedValueCard")
public class StoredValueCardController extends BaseController
{
    @Autowired
    private IStoredValueCardService storedValueCardService;

    /**
     * 通过储蓄卡名称和储蓄卡编码和储蓄卡类型查询储值卡列表
     */
    @ApiOperation("通过储蓄卡名称储蓄卡编码和储蓄卡类型查询储值卡列表")
    @PreAuthorize("@ss.hasPermi('system:card:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam (required = false) String cardName,@RequestParam (required = false) String cardCode,@RequestParam (required = false) String cardType)
    {
        startPage();
        List<StoredValueCard> list = storedValueCardService.selectStoredValueCardListByConditions(cardName,cardCode,cardType);
        return getDataTable(list);
    }

    /**
     * 导出储值卡列表
     */
    @ApiOperation("导出储值卡列表")
    @PreAuthorize("@ss.hasPermi('system:card:export')")
    @Log(title = "储值卡", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestParam (required = false) String cardName,@RequestParam (required = false) String cardCode,@RequestParam (required = false) String cardType)
    {
        List<StoredValueCard> list = storedValueCardService.selectStoredValueCardListByConditions(cardName,cardCode,cardType);
        ExcelUtil<StoredValueCard> util = new ExcelUtil<StoredValueCard>(StoredValueCard.class);
        util.exportExcel(response, list, "储值卡数据");
    }

    /**
     * 通过id获取储值卡详细信息
     */
    @ApiOperation("通过id获取储值卡详细信息")
    @PreAuthorize("@ss.hasPermi('system:card:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(storedValueCardService.selectStoredValueCardById(id));
    }

    /**
     * 新增储值卡
     */
    @ApiOperation("新增储值卡")
    @PreAuthorize("@ss.hasPermi('system:card:add')")
    @Log(title = "储值卡", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StoredValueCard storedValueCard)
    {
        return toAjax(storedValueCardService.insertStoredValueCard(storedValueCard));
    }

    /**
     * 修改储值卡
     */
    @ApiOperation("修改储值卡")
    @PreAuthorize("@ss.hasPermi('system:card:edit')")
    @Log(title = "储值卡", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StoredValueCard storedValueCard)
    {
        return toAjax(storedValueCardService.updateStoredValueCard(storedValueCard));
    }

    /**
     * 通过id批量删除储值卡信息
     */
    @ApiOperation("通过id批量删除储值卡信息")
    @PreAuthorize("@ss.hasPermi('system:card:remove')")
    @Log(title = "储值卡", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(storedValueCardService.deleteStoredValueCardByIds(ids));
    }
}
